﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfSnqkGasAnalysis.Model
{
    /// <summary>
    /// 消息返回接口
    /// </summary>
    public interface IResult
    {
        /// <summary>
        /// 操作代码，默认200表示操作成功，500表示异常
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 获取操作码枚举
        /// </summary>
        public ResultCode CodeEnum
        {
            get
            {
                return ((ResultCode)Code);
            }
        }

        /// <summary>
        /// 消息
        /// </summary>
        public string Msg { get; set; }

        /// <summary>
        /// 返回数据
        /// </summary>
        public object Data { get; set; }
    }


    /// <summary>
    /// Code 状态码枚举。
    /// </summary>
    public enum ResultCode
    {
        /// <summary>
        /// 执行成功
        /// </summary>
        Success = 200,

        /// <summary>
        /// 执行失败
        /// </summary>
        Fail = 500
    }

    /// <summary>
    /// 返回消息, Code默认200表示操作成功，500表示异常
    /// </summary>
    /// 2022-1-4 16:16:02 王浩力 添加
    public struct Result : IResult
    {
        public int Code { get => code; set { code = value; } }
        public string Msg { get => msg; set { msg = value; } }
        public object Data { get => data; set { data = value; } }

        /// <summary>
        /// 操作代码，默认200表示操作成功，500表示异常
        /// </summary>
        private int code;

        /// <summary>
        /// 消息
        /// </summary>
        private string msg;

        /// <summary>
        /// 返回数据
        /// </summary>
        private object data;

        /// <summary>
        /// code=200，表示成功
        /// </summary>
        /// <param name="data"></param>
        public Result(object _data)
        {
            code = (int)ResultCode.Success;
            data = _data;
            msg = "操作成功";
        }

        /// <summary>
        /// 默认返回错误消息，code=500表示错误消息
        /// </summary>
        /// <param name="_msg"></param>
        /// <param name="_code"></param>
        public Result(string _msg, int _code = (int)ResultCode.Fail)
        {
            code = _code;
            msg = _msg;
            data = null;
        }

    }

    public struct Result<T>
    {
        /// <summary>
        /// 操作代码，默认200表示操作成功，500表示异常
        /// </summary>
        public int Code;

        /// <summary>
        /// 返回数据，强类型
        /// </summary>
        public T Data;

        /// <summary>
        /// 消息
        /// </summary>
        public string Msg;

        public Result(T data)
        {
            Code = (int)ResultCode.Success;
            Data = data;
            Msg = "操作成功";
        }

        public Result(string msg, int code = (int)ResultCode.Fail)
        {
            Code = code;
            Msg = msg;
            Data = default;
        }

        public Result(T data, int code = (int)ResultCode.Success)
        {
            Code = code;
            Data = data;
            Msg = "操作成功";
        }

        public Result(T data, string msg = "", int code = (int)ResultCode.Success)
        {
            Code = code;
            Msg = msg;
            Data = data;
        }
    }

    /// <summary>
    /// 返回成功的消息对象。Code=200
    /// </summary>
    /// 创建时间：2022-12-10 14:53:19。
    public class ResultSuccess : IResult
    {
        private int code;
        private string msg;
        private object data;

        public ResultSuccess()
        {
            code = (int)ResultCode.Success;
            msg = "操作成功";
            data = null;
        }

        /// <summary>
        /// 返回成功的消息对象。Code=200
        /// </summary>
        /// <param name="_msg"></param>
        public ResultSuccess(string _msg = null)
        {
            code = (int)ResultCode.Success;
            msg = _msg;
            data = null;
        }

        /// <summary>
        /// 返回成功的消息对象。Code=200
        /// </summary>
        /// <param name="_msg"></param>
        /// <param name="_data">返回的数据</param>
        public ResultSuccess(string _msg, object _data)
        {
            code = (int)ResultCode.Success;
            msg = _msg;
            data = _data;
        }

        public int Code { get => code; set { code = value; } }
        public string Msg { get => msg; set { msg = value; } }
        public object Data { get => data; set { data = value; } }

    }
}
